#!/usr/bin/env python
#-*- coding: utf8 -*-
"""
Calc and print RA, DE, MAG from bright light stars catalog data.
Usage: python3 cat2.py > stars.txt
"""

import math

bigstars = {
    10144 : 'Achernar',
    122451 : 'Agena',
    108767 : 'Alchiba',
    29139 : 'Aldebaran',
    112185 : 'Alioth',
    120315 : 'Alkaid',
    187642 : 'Altair',
    148478 : 'Antares',
    124897 : 'Arcturus',
    39801 : 'Betelgeuse',
    45348 : 'Canopus',
    432 : 'Caph',
    60178 : 'Castor',
    34029 : 'Chapel',
    4128 : 'Diphda',
    164058 : 'Gianfar',
    218045 : 'Markab',
    8890 : 'Polaris',
    61421 : 'Procyon',
    34085 : 'Rigel',
    48915 : 'Sirius',
    116658 : 'Spica',
    172167 : 'Vega',
}

global starsdata
f = open('catalog.dat')
try:
    for line in f:
        #nStar = int(line[:4].strip() or 0)
        HD = int(line[25:31].strip() or 0)
        recString = line[75:81]

        raHH = float(recString[:2].strip() or 0)
        raMM = float(recString[2:4].strip() or 0)
        raSS = float(recString[4:6].strip() or 0)

        raValue = 15 * ( raHH + raMM / 60.0 + raSS / 3600.0 ) / 180.0 * math.pi

        decString = line[83:90]

        deSign = (1.0, -1.0)[decString[:1] == "-"] 
        deHH = float(decString[1:3].strip() or 0)
        deMM = float(decString[3:5].strip() or 0)
        deSS = float(decString[5:7].strip() or 0)

        deValue = deSign * ( deHH + deMM / 60.0 + deSS / 3600.0 ) / 180.0 * math.pi

        magString = line[102:107]
        magValue = float(magString.strip() or 0)

        if ( line and magValue < 6.0 ):
                print( [raValue, deValue, magValue, HD, bigstars.get(HD,'')] )
finally:
    f.close()

